home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / misc / emu / flamingo.lha / Flamingo / sources / CGX-Refresh.asm < prev    next >
Encoding:
Assembly Source File  |  2000-07-21  |  8.8 KB  |  514 lines

  1. ; CGX-Refresh driver (work on all CGFX 8bit screen)
  2. ; External Video Driver for
  3. ; Flaming Plus/4 emulator for the Amiga
  4. ;
  5. ; version 1.4
  6. ; 1.3: CV64 related modulo fix (18.05.99)
  7. ; 1.4: hi/truecolor screen refresh check (due. promoters) (30.06.99)
  8. ; 1.5: added config support (12.07.99)
  9. ; 1.6: Version level change (21.07.00 by Rachy)
  10.  
  11. TRUE    equ    1
  12. FALSE    equ    0
  13.  
  14.         INCDIR    Include:
  15.  
  16.     INCLUDE exec/types.i
  17.     INCLUDE    exec/memory.i
  18.     INCLUDE    exec/exec_lib.i
  19.     INCLUDE    utility/tagitem.i
  20.     INCLUDE    intuition/intuition.i
  21.     INCLUDE    intuition/intuition_lib.i
  22.     INCLUDE    intuition/screens.i
  23.     INCLUDE graphics/modeid.i
  24.     INCLUDE    graphics/rastport.i
  25.     INCLUDE    libraries/cybergraphics_lib.i
  26.     INCLUDE    cybergraphics/cybergraphics.i
  27.     INCLUDE    graphics/graphics_lib.i
  28.     INCLUDE    dos/dos_lib.i
  29.     INCLUDE    dos/dostags.i
  30.     INCLUDE    dos/dosextens.i
  31.     INCLUDE    dos/var.i
  32.  
  33. ;*** Handler structure
  34.  
  35.  STRUCTURE vxd_handler,0
  36.   LONG intuibase
  37.   LONG myscr
  38.   LONG mywin
  39.   WORD xsize
  40.   WORD ysize
  41.   LONG palette
  42.   LONG palette32
  43.   LONG emuscr
  44.  
  45.   LONG gfxbase
  46.   LONG cybscrbitmap        ;bitmapstuff
  47.   LONG cybbase
  48.   LONG dosbase
  49.   LONG screendim
  50.  LABEL    vxd_handler_SIZEOF
  51.  
  52.  
  53. JSRLIB    MACRO
  54.     jsr    _LVO\1(a6)
  55.     ENDM
  56.  
  57. ;*** Let's begin
  58.  
  59.     moveq.l    #0,d0
  60.     rts
  61.  
  62.     dc.b "FLAMINGOXVD"
  63.     dc.b "2"
  64.  
  65.     dc.l Name
  66.     dc.l Author
  67.     dc.w 1
  68.     dc.w 6
  69.  
  70.     dc.l drv_Init
  71.     dc.l drv_Done
  72.     dc.l drv_Configure
  73.     dc.l drv_OpenScreen
  74.     dc.l drv_CloseScreen
  75.     dc.l drv_Refresh
  76.     dc.l 0            ;No PPC refresh
  77.  
  78. Name:    dc.b    "CGX-Refresh External Video Driver 1.6 (21.07.00)",0
  79. Author:    dc.b    "László (pH03N1x) Török",0
  80.  
  81.     EVEN
  82.  
  83. ;*** Functions
  84.  
  85. drv_Init:
  86.     movem.l    a0-a1,-(sp)    ;Saving infos
  87.     move.l  4.w,a6        ;Alloc memory for handler
  88.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  89.     move.l    #vxd_handler_SIZEOF,d0
  90.     JSRLIB    AllocVec
  91.     movem.l    (sp)+,a0-a1    ;Recover infos
  92.  
  93.         tst.l    d0
  94.     beq.b    b1        ;No mem
  95.     movea.l    d0,a2
  96.         move.l    8(a0),intuibase(a2)    ;Saving intuition.library base
  97.         move.l    4(a0),dosbase(a2)    ;Saving dos.library base
  98.     move.l    (a0),gfxbase(a2)
  99.  
  100.         movem.l    d0,-(sp)
  101.     move.l    dosbase(a2),a6        ;Reading config file
  102.     move.l    #configfile,d1        ;Config file is pretty simple:
  103.     move.l    #MODE_OLDFILE,d2    ;only a screenmode number
  104.     JSRLIB    Open
  105.     tst.l    d0
  106.     beq.b    .2            ;Failed open
  107.     move.l    d0,d1
  108.     move.l    (sp),a0
  109.     lea    screendim(a0),a0
  110.     move.l    a0,d2
  111.     moveq.l    #4,d3
  112.     movem.l    d0,-(sp)
  113.     JSRLIB    Read            ;Reading the 4 bytes
  114.     cmp.l    #4,d0
  115.     beq.b    .3
  116.     move.l    (sp),a0            ;Failed: set 0 instead garbage
  117.     move.l    #0,screendim(a0)
  118.  
  119. .3    movem.l    (sp)+,d1
  120.     JSRLIB    Close
  121.  
  122. .2    movem.l    (sp)+,d0
  123.  
  124. b1:    move.l    #err_nomem,d1        ;Ignored, if D0 not 0
  125.     rts                ;Result in D0 available for now
  126.  
  127.  
  128.  
  129. drv_Done:
  130.     movea.l    a0,a1
  131.     cmp.l    #0,a1
  132.     beq.b    c1
  133.     move.l    4.w,a6    
  134.     JSRLIB    FreeVec        ;Deallocate handler
  135. c1
  136.     rts
  137.  
  138. drv_Configure:            ;Configure
  139.                 ;A simple screenmode requester appears
  140.     movem.l    a0,-(sp)
  141.  
  142.     move.l    a0,a5
  143.     move.l    screendim(a5),ScrDisplayID
  144.  
  145.     moveq    #$00,d0
  146.     moveq    #$00,d1
  147.     move.w    xsize(a5),d0
  148.     move.w    ysize(a5),d1
  149.  
  150.     move.l    d0,cgfxmodewidth
  151.     move.l    d1,cgfxmodeheight
  152.  
  153.     move.l    4.w,a6
  154.     lea    cyblib(pc),a1
  155.     moveq    #40,d0
  156.     jsr    _LVOOpenLibrary(a6)
  157.     move.l    d0,cybbase(a5)
  158.     beq.b    configbug
  159.  
  160.     move.l    cybbase(a5),a6
  161.     lea    cybreqtags(pc),a1
  162.     jsr    _LVOCModeRequestTagList(a6)
  163.  
  164.     cmp.l    #INVALID_ID,d0
  165.     bne.b    config2
  166.  
  167.     move.l    (4).w,a6
  168.     move.l    cybbase(a5),a1
  169.     jsr    _LVOCloseLibrary(a6)
  170.     clr.l    cybbase(a5)
  171.  
  172. configbug:
  173.     suba.l    a0,a0
  174.     move.l    intuibase(a5),a6
  175.     jsr    _LVODisplayBeep(a6)
  176.     move.l    (sp)+,a0
  177.     rts
  178.  
  179. config2:
  180.     move.l    d0,screendim(a5)
  181.     
  182.     move.l    dosbase(a5),a6        ;Writing config file
  183.     move.l    #configfile,d1        ;Config file is pretty simple:
  184.     move.l    #MODE_NEWFILE,d2    ;only a screenmode number
  185.     JSRLIB    Open
  186.     tst.l    d0
  187.     beq.b    .1            ;Failed open
  188.     move.l    d0,d1
  189.     move.l    (sp),a0
  190.     lea    screendim(a0),a0
  191.     move.l    a0,d2
  192.     moveq.l    #4,d3
  193.     movem.l    d0,-(sp)
  194.     JSRLIB    Write            ;Writing the 4 bytes
  195.  
  196.     movem.l    (sp)+,d1        ;We don't care too much on
  197.     JSRLIB    Close            ;success...
  198.  
  199. .1
  200.     move.l    (4).w,a6
  201.     move.l    cybbase(a5),a1
  202.     jsr    _LVOCloseLibrary(a6)
  203.     clr.l    cybbase(a5)
  204.  
  205.     movem.l    (sp)+,a0
  206.     rts
  207.  
  208.  
  209. drv_OpenScreen:
  210.     movea.l a0,a5
  211.  
  212.     move.l    screendim(a0),ScrDisplayID
  213.  
  214.     move.w    (a1)+,xsize(a5)
  215.     move.w    (a1)+,ysize(a5)
  216.     move.l    (a1)+,palette(a5)
  217.  
  218.     move.l    4.w,a6
  219.     lea    cyblib(pc),a1
  220.     moveq    #40,d0
  221.     jsr    _LVOOpenLibrary(a6)
  222.     move.l    d0,cybbase(a5)
  223.     beq.w    e0
  224.  
  225.  
  226.  
  227.     move.w    xsize(a5),cybwidth+2
  228.     move.w    ysize(a5),cybheight+2
  229.  
  230.     tst.l    ScrDisplayID
  231.     bne    modeisready
  232.  
  233.  
  234.     moveq    #$00,d0
  235.     moveq    #$00,d1
  236.     move.w    xsize(a5),d0
  237.     move.w    ysize(a5),d1
  238.  
  239.     move.l    cybbase(a5),a6
  240.     lea    cybmodetags(pc),a0
  241.     jsr    _LVOBestCModeIDTagList(a6)
  242.     move.l    d0,ScrDisplayID
  243.  
  244.  
  245. modeisready:
  246.  
  247.  
  248.     moveq.l    #0,d0
  249.     move.l    d0,d1
  250.     move.w    xsize(a5),d0
  251.     move.w    ysize(a5),d1
  252.     mulu.w    d1,d0
  253.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  254.     move.l    4.w,a6
  255.     JSRLIB    AllocVec
  256.     move.l    d0,emuscr(a5)        ;allocating emulator screen
  257.  
  258.  
  259.     move.l    4.w,a6
  260.     move.l    #MEMF_PUBLIC,d1
  261.     move.l    #128*3*4+8,d0
  262.     JSRLIB    AllocVec
  263.     move.l    d0,palette32(a5)    ;Convert palette to 32 bit per gun
  264.     beq.w    e1
  265.     movea.l    d0,a0
  266.         move.l    palette(a5),a1
  267.     move.w    #128,(a0)+
  268.     move.w    #$0,(a0)+
  269.     move.l    #128*3-1,d2
  270. e2    moveq.l    #0,d0
  271.     move.b    (a1)+,d0
  272.     swap    d0
  273.     asl.l    #8,d0
  274.     move.l    d0,(a0)+
  275.     dbf    d2,e2
  276.     move.l    #0,(a0)
  277.     move.w    xsize(a5),width+2
  278.     move.w    ysize(a5),height+2
  279.     move.l    palette32(a5),pal
  280.  
  281.         suba.l    a0,a0            ;No newscreen stuct
  282.         lea    scrtags,a1
  283.     movea.l    intuibase(a5),a6
  284.     JSRLIB    OpenScreenTagList
  285.  
  286.     move.l    d0,wscr
  287.     move.l    d0,myscr(a5)
  288.     beq.b    e1
  289.  
  290.  
  291.     move.l    d0,a1
  292.     lea    sc_RastPort(a1),a1
  293.     move.l    rp_BitMap(a1),a0
  294.     move.l    a0,cybscrbitmap(a5)
  295.  
  296.     movea.l    intuibase(a5),a6
  297.     move.w    xsize(a5),wwidth+2
  298.     move.w    ysize(a5),wheight+2
  299.     suba.l    a0,a0
  300.     lea    wintags,a1
  301.     JSRLIB    OpenWindowTagList
  302.     move.l    d0,mywin(a5)
  303.     beq.b    e1
  304.     movea.l    d0,a1
  305.  
  306.     move.l  wd_UserPort(a1),d0    ;IDCMP port
  307.     move.l    emuscr(a5),d2        ;chunky buffer
  308.     moveq    #$00,d3            ;no modulo
  309.  
  310. e0:    move.l    #err_cyblib,d1
  311.     rts
  312.  
  313.  
  314. e1    move.l    #err_noscr,d1
  315.     rts
  316.  
  317. drv_CloseScreen:
  318.  
  319.     move.l    a0,a5
  320.     
  321.     tst.l    cybbase(a5)
  322.     beq.b    nemcyb
  323.     move.l    (4).w,a6
  324.     move.l    cybbase(a5),a1
  325.     jsr    _LVOCloseLibrary(a6)
  326.     clr.l    cybbase(a5)
  327.  
  328. nemcyb:    move.l    intuibase(a5),a6
  329.     move.l    mywin(a5),a0
  330.     cmp.l    #0,a0
  331.     beq.b    f1
  332.     JSRLIB    CloseWindow
  333.  
  334. f1    move.l    myscr(a5),a0
  335.     cmp.l    #0,a0
  336.     beq.b    f2
  337.     JSRLIB    CloseScreen
  338.  
  339. f2    movea.l    palette32(a5),a1
  340.         cmp.l    #0,a1
  341.     beq.b    f3
  342.     move.l    4.w,a6
  343.     JSRLIB    FreeVec        ;Deallocate translated palette
  344.  
  345.  
  346. f3    movea.l    emuscr(a5),a1
  347.         cmp.l    #0,a1
  348.     beq.b    f4
  349.     move.l    4.w,a6
  350.     JSRLIB    FreeVec        ;Deallocate translated palette
  351.  
  352.  
  353. f4:    move.l    d0,emuscr(a5)    ;They were already freed
  354.     move.l    d0,palette32(a5)
  355.     move.l    d0,myscr(a5)
  356.     move.l    d0,mywin(a5)
  357.  
  358.     rts
  359.  
  360. drv_Refresh:
  361.  
  362.     move.l    emuscr(a0),d7
  363.  
  364.     move.l    d7,a4
  365.     move.l    a4,a5
  366.  
  367.     moveq    #$00,d5
  368.     move.w    xsize(a0),d5
  369.     move.l    d5,d3
  370.  
  371.     moveq    #$00,d6
  372.     move.w    ysize(a0),d6
  373.     subq.l    #1,d6
  374.  
  375.     move.l    cybbase(a0),a6
  376.     move.l    cybscrbitmap(a0),a0
  377.     lea    cgfxlocktags(pc),a1
  378.     jsr    _LVOLockBitMapTagList(a6)    ;d0 = lock
  379.  
  380.     cmp.l    #1,bytesperpix
  381.     bne.b    norefresh            ;nem 8 bites a screen, szoval nincs refresh
  382.  
  383.     move.l    GfxBoardBitmapWidth(pc),d4    ;modulo (CV64 miatt ez az egyeduli korrekt mod)
  384.  
  385.     asr.l    #2,d5            ;/4 (long copy)
  386.     subq.l    #1,d5
  387.  
  388.     move.l    gfxboarddirectmem(pc),a3    ;a3 dest address
  389.     move.l    a3,a2
  390.  
  391. yloop:    move.l    d5,d2
  392. xloop:    move.l    (a4)+,(a3)+
  393.     dbf    d2,xloop
  394.  
  395.     add.l    d3,a5
  396.     move.l    a5,a4                ;next line (source)
  397.  
  398.     add.l    d4,a2
  399.     move.l    a2,a3                ;next line (dest)
  400.  
  401.     dbf    d6,yloop
  402.  
  403. norefresh:
  404.     move.l    d0,a0                ;bitlock
  405.  
  406.     jsr    _LVOUnLockBitMap(a6)
  407.  
  408.     move.l    d7,d0
  409.         RTS
  410.  
  411. ;*** Constants
  412.  
  413.  
  414. cyblib:        dc.b    "cybergraphics.library",0
  415.  
  416.  
  417. scrtags:
  418.     dc.l    SA_Width
  419. width:    dc.l    0
  420.     dc.l    SA_Height
  421. height:    dc.l    0
  422.     dc.l    SA_Depth,8
  423.     dc.l    SA_Colors32
  424. pal:    dc.l    0
  425.     dc.l    SA_Title,scrtitle
  426.     dc.l    SA_ShowTitle,FALSE
  427.     dc.l    SA_DisplayID
  428.  
  429. ScrDisplayID:
  430.     dc.l    0
  431.  
  432.     dc.l    SA_Type,CUSTOMSCREEN
  433.     dc.l    SA_AutoScroll,TRUE
  434.     dc.l    SA_Overscan,OSCAN_STANDARD
  435.     dc.l    SA_Quiet,TRUE
  436.     dc.l    TAG_DONE
  437.  
  438. wintags:
  439.     dc.l    WA_Left,0
  440.     dc.l    WA_Top,0
  441.     dc.l    WA_Width
  442. wwidth:    dc.l    0
  443.     dc.l    WA_Height
  444. wheight:    dc.l    0
  445.     dc.l    WA_IDCMP,IDCMP_RAWKEY
  446.     dc.l    WA_Title,0
  447.     dc.l    WA_Backdrop,TRUE
  448.     dc.l    WA_RMBTrap,TRUE
  449.     dc.l    WA_Borderless,TRUE
  450.     dc.l    WA_NoCareRefresh,TRUE
  451.     dc.l    WA_CustomScreen
  452. wscr:    dc.l    0
  453.     dc.l    WA_SimpleRefresh,TRUE
  454.     dc.l    WA_Activate,TRUE
  455.     dc.l    TAG_DONE
  456.  
  457. scrtitle:    dc.b    'Flamingo Plus/4 emulator screen',0
  458.         EVEN
  459.  
  460. configfile:    dc.b    'cgfx-refresh.cfg',0
  461.         EVEN
  462.  
  463. cybmodetags:
  464.         dc.l    CYBRBIDTG_Depth,8
  465.         dc.l    CYBRBIDTG_NominalWidth
  466. cybwidth:    dc.l    0        
  467.         dc.l    CYBRBIDTG_NominalHeight
  468. cybheight:    dc.l    0
  469.         dc.l    TAG_END
  470.  
  471. cgfxlocktags:    dc.l    LBMI_BASEADDRESS
  472.         dc.l    gfxboarddirectmem
  473.         dc.l    LBMI_BYTESPERROW
  474.         dc.l    GfxBoardBitmapWidth    
  475.         dc.l    LBMI_BYTESPERPIX
  476.         dc.l    bytesperpix            ;egy kis check a kreativ userek (promoter) miatt
  477.  
  478.         dc.l    TAG_END
  479.  
  480. gfxboarddirectmem:
  481.         dc.l    0
  482. GfxBoardBitmapWidth:
  483.         dc.l    0
  484. bytesperpix:    dc.l    0        
  485.  
  486.  
  487. cybreqtags:    
  488.         dc.l    CYBRMREQ_MinWidth
  489. cgfxmodewidth:    dc.l    0        
  490.         dc.l    CYBRMREQ_MinHeight
  491. cgfxmodeheight:    dc.l    0
  492.         dc.l    CYBRMREQ_MinDepth
  493. cgfxmodedepth:    dc.l    8
  494.         dc.l    CYBRMREQ_MaxDepth
  495. cgfxmaxdepth:    dc.l    8
  496.         dc.l    CYBRMREQ_CModelArray
  497. cgfxpixform:    dc.l    cybreqcolors256
  498.         dc.l    TAG_END
  499.  
  500. cybreqcolors256:
  501.         dc.l    PIXFMT_LUT8
  502.         dc.l    TAG_END
  503.  
  504.  
  505. ;*** Errors
  506.  
  507. err_nomem:
  508.     dc.b    'Ran out of memory',0
  509. err_noscr:
  510.     dc.b    'Cannot open screen',0
  511. err_cyblib:
  512.     dc.b    'Cannot open cybergraphics.library v40+',0
  513.  
  514.